package sg.nus.iss.vmcs.dao;

import sg.nus.iss.vmcs.VMCSException;

/**
 * Factory for the various DAOs, loaded using Property Files
 * Factory is singleton
 * @author Seng Chia How
 *
 */
public class PropertyDAOFactory extends VmcsDAOFactory {

	private static PropertyDAOFactory instance;
	private PropertyStoreDAO aStoreDAO;
	private PropertyCoinRegistryDAO aCoinRegistryDAO;
	
	//Singleton, hides default constructor
	private PropertyDAOFactory(){
	}
	
	public static PropertyDAOFactory getInstance(){
		if(instance == null){
			instance = new PropertyDAOFactory();
		}
		return instance;
	}
	
	/**
	 * Gets a Property Store DAO instance
	 * Enforce that creation is performed only once
	 */
	public StoreDAO getStoreDAO() {
		try {
			if (aStoreDAO == null)
				aStoreDAO =  new PropertyStoreDAO();
				
			return aStoreDAO;
		} 
		catch (VMCSException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * Gets a Coin Registry DAO instance
	 * Enforce that creation is performed only once
	 */
	public CoinRegistryDAO getCoinRegistryDAO() {
		try {
			if (aCoinRegistryDAO == null)
				aCoinRegistryDAO = new PropertyCoinRegistryDAO();
			
			return aCoinRegistryDAO;
		} 
		catch (VMCSException e) {
			e.printStackTrace();
		}
		return null;
	}
}
